
def ai [text: string] {
    let token = open .env | from toml | get bd_qianfan_token
    let url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + $token
    http post -t application/json $url { messages: [{ role:"user","content": $text }]} | get result usage.total_tokens 
}

# description: "todo"
def check [] {
    ls content/posts/**/*.md | each { |it| open $it.name |  split row "---" | get 1 | from yaml | select title description? | merge $it | select name description? } | where {|it| $it.description? == "todo" }
}

def getText [name: string] {
    open $name | split row "---" | get 2
}

def getYaml [name: string] {
    open $name | split row "---" | get 1
}

def main [x: int] {
    let filename = check | get 0 | get name
    getYaml $filename | from yaml 
    # 选择第一个
    # let filename = check | get 0 | get name 
    # let text = getText $filename
    # let promt = "总结摘要: " + $text
    # ai $promt
}